<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt">
    <ul id="app">

    </ul>
    <script>
        var arr = []
        var txt = document.getElementById("txt")
        var app = document.getElementById("app")
        txt.onkeydown = function(event){
            if(event.keyCode == 13){
                /* indexOf  arr.indexOf(value)  获取数组的下标  没有的返回-1  */
                if(arr.indexOf(this.value) == -1 && this.value!=""){
                    arr.push(this.value)
                    var li = document.createElement("li")
                    li.innerHTML = this.value
                    app.append(li)
                }
                console.log(arr);
            }
        }
    </script>
</body>
</html>